using System;
using BruteForce;
using BruteForce.NewManagers;
using BruteForce.UserInterface.Abstracts;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace Bruteforce.UserInterface.UIControls
{
    
    public class DynamicButton : AbstractUIControl
    {
        public Texture2D Image1;
        public Texture2D Image2;

        public event OnClickHandler OnClick;

        delegate Boolean DelegateFunction();
        private DelegateFunction _showFirstImage; 

        public DynamicButton(Texture2D image1,Texture2D image2, string name, Rectangle surroundingRectangle,Func<Boolean> method)
            : base(name, surroundingRectangle)
        {
            Image1 = image1;
            Image2 = image2;
            _showFirstImage = new DelegateFunction(method);
        }



        public override void Update()
        {
            if (InputManager.Instance.MouseClicked.IsChangedSince(BFGame.LoopIndex) &&
                InputManager.Instance.IsMouseClickedOn(CurrentUIcontrolRectangle))
            {
                if (OnClick != null && _showFirstImage()) OnClick();
            }
        }

        public override void Draw(GameTime gameTime)
        {
            Texture2D img;
            if (_showFirstImage())
                img=Image1;
            else img=Image2;

            BFGame.SpriteBatch.Draw(img,
                        new Rectangle(CurrentUIcontrolRectangle.X, CurrentUIcontrolRectangle.Y,
                                        RelativeUIcontrolRectangle.Width, RelativeUIcontrolRectangle.Height),
                        Color.White);
        }


    }
}